
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Nginx配置 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="PROXY.html" />
    
    
    <link rel="prev" href="PERMISSION.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="START.html">
            
                <a href="START.html">
            
                    
                    快速开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="MENU.html">
            
                <a href="MENU.html">
            
                    
                    菜单配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="PAGE.html">
            
                <a href="PAGE.html">
            
                    
                    页面开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="ROUTE.html">
            
                <a href="ROUTE.html">
            
                    
                    系统路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="AJAX.html">
            
                <a href="AJAX.html">
            
                    
                    Ajax请求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="MOCK.html">
            
                <a href="MOCK.html">
            
                    
                    Mock模拟数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="STYLE.html">
            
                <a href="STYLE.html">
            
                    
                    样式&主题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="LAYOUT.html">
            
                <a href="LAYOUT.html">
            
                    
                    导航布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="MODEL.html">
            
                <a href="MODEL.html">
            
                    
                    Model(Redux)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="I18N.html">
            
                <a href="I18N.html">
            
                    
                    国际化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="PERMISSION.html">
            
                <a href="PERMISSION.html">
            
                    
                    权限控制
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.13" data-path="NGINX.html">
            
                <a href="NGINX.html">
            
                    
                    Nginx配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="PROXY.html">
            
                <a href="PROXY.html">
            
                    
                    开发代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="OTHER.html">
            
                <a href="OTHER.html">
            
                    
                    其他
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Nginx配置</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="nginx&#x914D;&#x7F6E;&#x53C2;&#x8003;">nginx&#x914D;&#x7F6E;&#x53C2;&#x8003;</h1>
<p>&#x8FD9;&#x91CC;&#x53EA;&#x662F;&#x53C2;&#x8003;&#x6587;&#x4EF6;&#xFF0C;&#x6839;&#x636E;&#x81EA;&#x5DF1;&#x7684;&#x9879;&#x76EE;&#x9700;&#x6C42;&#x81EA;&#x884C;&#x914D;&#x7F6E;</p>
<pre><code class="lang-nginx"><span class="hljs-comment"># &#x540E;&#x7AEF;&#x670D;&#x52A1;&#x5730;&#x5740;</span>
<span class="hljs-attribute">upstream</span> api_service {
  <span class="hljs-attribute">server</span> xxx.xxx.xxx.xxx:xxxx;
  <span class="hljs-attribute">keepalive</span> <span class="hljs-number">2000</span>;
}

<span class="hljs-section">server</span> {
    <span class="hljs-attribute">listen</span>       <span class="hljs-number">80</span>;
    <span class="hljs-attribute">server_name</span>  xxx.com;
    <span class="hljs-attribute">root</span> /usr/local/nginx/html;
    <span class="hljs-attribute">location</span> / {
      <span class="hljs-attribute">index</span> index.html;
      <span class="hljs-attribute">try_files</span> <span class="hljs-variable">$uri</span> <span class="hljs-variable">$uri</span>/ /index.html; <span class="hljs-comment">#react-router &#x9632;&#x6B62;&#x9875;&#x9762;&#x5237;&#x65B0;&#x51FA;&#x73B0;404</span>
    }

    <span class="hljs-comment"># &#x9759;&#x6001;&#x6587;&#x4EF6;&#x7F13;&#x5B58;&#xFF0C;&#x542F;&#x7528;Cache-Control: max-age&#x3001;Expires</span>
    <span class="hljs-attribute">location</span> <span class="hljs-regexp">~ ^/(css|js|media)/</span> {
      <span class="hljs-attribute">expires</span> <span class="hljs-number">10y</span>;
      <span class="hljs-attribute">access_log</span> <span class="hljs-literal">off</span>;
      <span class="hljs-attribute">add_header</span> Cache-Control <span class="hljs-string">&quot;public&quot;</span>;
    }

    <span class="hljs-comment"># &#x4EE3;&#x7406;ajax&#x8BF7;&#x6C42;</span>
    <span class="hljs-attribute">location</span><span class="hljs-regexp"> ^~/api</span> {
       <span class="hljs-attribute">rewrite</span><span class="hljs-regexp"> ^/api/(.*)$</span> /<span class="hljs-variable">$1</span> <span class="hljs-literal">break</span>; <span class="hljs-comment"># &#x5982;&#x679C;&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x4E0D;&#x662F;&#x7EDF;&#x4E00;&#x4EE5;api&#x5F00;&#x5934;&#xFF0C;&#x53BB;&#x6389;api&#x524D;&#x7F00;</span>
       <span class="hljs-attribute">proxy_pass</span> http://api_service/;
       <span class="hljs-attribute">proxy_set_header</span> Host  <span class="hljs-variable">$http_host</span>;
       <span class="hljs-attribute">proxy_set_header</span> Connection close;
       <span class="hljs-attribute">proxy_set_header</span> X-Real-IP <span class="hljs-variable">$remote_addr</span>;
       <span class="hljs-attribute">proxy_set_header</span> X-Forwarded-Server <span class="hljs-variable">$host</span>;
    }
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="PERMISSION.html" class="navigation navigation-prev " aria-label="Previous page: 权限控制">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="PROXY.html" class="navigation navigation-next " aria-label="Next page: 开发代理">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Nginx配置","level":"1.13","depth":1,"next":{"title":"开发代理","level":"1.14","depth":1,"path":"PROXY.md","ref":"PROXY.md","articles":[]},"previous":{"title":"权限控制","level":"1.12","depth":1,"path":"PERMISSION.md","ref":"PERMISSION.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"NGINX.md","mtime":"2019-02-16T09:08:05.324Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-17T03:27:10.809Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

